package com.sanhuo.idms.service;

import com.sanhuo.idms.dao.ElectricScheduleWeekMapper;
import com.sanhuo.idms.entity.ElectricScheduleWeek;
import com.sanhuo.triild.Basic.BaseMapper;
import com.sanhuo.triild.Basic.BaseService;
import com.sanhuo.triild.annotation.MapperWire;
import com.sanhuo.utils.basic.Dateutil;
import com.sanhuo.utils.basic.StringUtil;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;
import java.util.Map;

@Service
@Transactional
public class ElectricSheduleWeekService extends BaseService<ElectricScheduleWeek> {
    @MapperWire
    private ElectricScheduleWeekMapper electricScheduleWeekMapper;

    @Override
    public BaseMapper<ElectricScheduleWeek> getBaseMapper() {
        return electricScheduleWeekMapper;
    }


    public void save(String dormId, double consume) throws ParseException {
        ElectricScheduleWeek week = new ElectricScheduleWeek();
        week.setId(StringUtil.UUID());
        week.setConsume(consume);
        week.setDormId(dormId);
        week.setCreateTime(Dateutil.getToday());
        save(week);
    }

    public List<Double> consumeWeek(String dormId) throws ParseException {
        Map<String, Date> map = Dateutil.getWeek();
        SimpleDateFormat sdf = new SimpleDateFormat(Dateutil.dateTime);
        return electricScheduleWeekMapper.findWeekByDorm(dormId, sdf.format(map.get(Dateutil.WEEK_FIRST))
                , sdf.format(map.get(Dateutil.WEEK_LAST)));
    }
}
